The repetition of a prefix operator (not
or ~
) is usually a typo. The second operator invalidates the first one:
a = False
b = ~~a # Noncompliant: equivalent to "a"
While calling not
twice is equivalent to calling the bool()
built-in function, the latter increases the code readability,
so it should be preferred.
a = 0
b = not not a # Noncompliant: use bool()
Exceptions
The rule does not raise an issue if the ~
function is overloaded in a customized class, as it is assumed to be the expected usage.